package com.test.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import com.test.po.User;


@Service("userServices")//别名
public class UserServiceImpl implements UserService {

	@Resource
    private JdbcTemplate jdbcTemplate;
	
	@Override
	public List<User> queryAllStudent() {
		//SQL
        String sql = "SELECT *  FROM User ";
        //结果
        List<User> list = jdbcTemplate.query(sql, new RowMapper<User>() {
            //映射每行数据  
            @Override
            public User mapRow(ResultSet rs, int rowNum) throws SQLException {
            	User user = new User();
            	user.setId(rs.getInt("id"));
            	user.setName(rs.getString("name"));
            	user.setAge(rs.getInt("age"));
            	user.setPassword(rs.getString("password"));
                return user;
            }

        });
        //返回结果
        return list;

	}

}
